package com.qilin.hscs.hm.convert;

import com.qilin.hscs.hm.dto.*;
import com.qilin.hscs.hm.enums.DeviceClusterEnum;
import com.qilin.hscs.hm.pojo.*;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by 10188 on 2018/3/31.
 */
public class DTO2DOConvert {

    public static List<Device> deviceDto2DeviceList(DeviceDto deviceDto) {
        List<Device> devices = new ArrayList<>();
        List<DeviceEPDto> eps = deviceDto.getEps();
        for (DeviceEPDto ep : eps) {
            Device device=new Device();
            BeanUtils.copyProperties(ep, device);
            BeanUtils.copyProperties(deviceDto, device);
            String ieee=StringUtils.join(deviceDto.getIeee(),",");
            String uid=StringUtils.join(deviceDto.getUid(),",");
            device.setIeee(ieee);
            device.setUid(uid);
            devices.add(device);
        }
        return devices;
    }

    public static Device singleBaseDeviceDto2Device(SingleBaseDeviceEPDto baseDeviceEPDto) {
        String ieee=StringUtils.join(baseDeviceEPDto.getIeee(),",");
        String uid=StringUtils.join(baseDeviceEPDto.getUid(),",");
        Device device=new Device();
        BeanUtils.copyProperties(baseDeviceEPDto, device);
        device.setIeee(ieee);
        device.setUid(uid);
        return  device;
    }

    public static Scene SceneDto2Sence(SceneDto sceneDto) {
        Scene scene = new Scene();
        BeanUtils.copyProperties(sceneDto, scene);
        return scene;
    }
    public static Room RoomDto2Room(RoomDto dto) {
        Room room = new Room();
        BeanUtils.copyProperties(dto, room);
        return room;
    }
    public static MutiController MutiControllerDto2MutiController(MuticontrollerDto muticontrollerDto){
        MutiController mutiController = new MutiController();
        BeanUtils.copyProperties(muticontrollerDto, mutiController);
        return mutiController;
    }
    public static MuticontollerDevice MutcontollerDeviceDto2MutcontollerDevice(MuticontrollerDeviceDto muticontrollerDeviceDto){
        MuticontollerDevice mutcontollerDevice = new MuticontollerDevice();
        BeanUtils.copyProperties(muticontrollerDeviceDto, mutcontollerDevice);
        return mutcontollerDevice;
    }
}
